package com.keeley.spider.server;

/**
 * Created with IntelliJ IDEA.
 * User: Tianjun
 * Date: 14-9-29
 * Time: 上午11:20
 *  责任链 + 工厂模式
 */
public abstract class AbsSpiderFacade {
    private AbsSpiderFacade nextFacade;

    public void setNextFacade(AbsSpiderFacade nextFacade) {
        this.nextFacade = nextFacade;
    }

    public boolean checkUpdate(String apkName) throws Exception{
        boolean flag =false;
        try{
            flag = this.process(apkName);
        }catch (Exception e){
            throw new RuntimeException(e);
        }finally {
            if(!flag && nextFacade!=null){
                return nextFacade.checkUpdate(apkName);
            }
        }
        return flag;
    }

    protected abstract boolean process(String apkName) throws Exception;

    public static AbsSpiderFacade createBaiduFacade(){
        return new SpiderServerFacade(new BaiduSpriderServer("百度助手"));
    }
    public static AbsSpiderFacade create360Facade(){
        return new SpiderServerFacade( new Z360SpriderServer("360助手"));
    }

}
